<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>e-shop</title>
    <meta name="description" content="e-shop">
    <meta name="keywords" content="e-shop">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
        .el-main {
            position: absolute;
            top: 70px;
            bottom: 0px;
            left: 200px;
            right: 10px;
            padding: 0;
        }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<div id="app">
    <el-container>
        <el-header class="main-header" style="height:70px;">
            <nav class="navbar navbar-static-top" :class=''>
                <!-- Logo -->
                <a href="#" class="logo" style="text-align:center">
                    <span class="logo-lg"> <img src=""></span>
                </a>
                <div class="right-menu">
                    <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                    <el-dropdown class="avatar-container right-menu-item" trigger="click">
                        <div class="avatar-wrapper">
                            <img src="../img/user2-160x160.jpg" class="user-avatar">
                            admin
                        </div>

                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item divided>
                                <span style="display:block;" @click="handleCreate()">修改密码</span>
                                <!--                                <el-button @click="handleCreate()">修改密码</el-button>-->
                            </el-dropdown-item>
                            <el-dropdown-item divided>
                                <span style="display:block;" @click="logout()">注销</span>
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </nav>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu>
                    <el-submenu v-for="menu in menuList" :index="menu.path">
                        <template slot="title">
                            <i class="fa" :class="menu.icon"></i>
                            {{menu.title}}
                        </template>
                        <template v-for="child in menu.children">
                            <el-menu-item :index="child.path">
                                <a :href="child.linkUrl" target="right">{{child.title}}</a>
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-container>
                <iframe name="right" class="el-main" src="novel_list.html" width="100%" height="580px"
                        frameborder="0"></iframe>
            </el-container>
        </el-container>
    </el-container>

    <!-- 新增标签弹层 -->
    <div class="add-form">
        <el-dialog title="修改密码" :visible.sync="dialogFormVisible">
            <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">

                <el-row>
                    <el-col :span="24">
                        <el-form-item label="用户名" prop="userName">
                            <el-input v-model="formData.userName"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="密码" prop="password">
                            <el-input v-model="formData.password" type="password"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="新密码" prop="newPassword">
                            <el-input v-model="formData.newPassword" type="password"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取消</el-button>
                <el-button type="primary" @click="handleEdit()">确定</el-button>
            </div>
        </el-dialog>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            menuList: [
                {
                    "path": "1",
                    "title": "工作台",
                    "icon": "fa-dashboard",
                    "children": []
                },
                {
                    "path": "2",
                    "title": "书架管理",
                    "icon": "fa-stethoscope",
                    "children": [
                        {
                            "path": "/2-1",
                            "title": "小说列表",
                            "linkUrl": "novel_list.html",
                            "children": []
                        },
                        {
                            "path": "/2-2",
                            "title": "小说章节列表",
                            "linkUrl": "novelDetails_list.html",
                            "children": []
                        }
                        /*{
                            "path": "/2-3",
                            "title": "会员统计",
                            "linkUrl": "all-item-list.html",
                            "children": []
                        },*/
                    ]
                },
                {
                    "path": "3",
                    "title": "系统管理",
                    "icon": "fa-stethoscope",
                    "children": [
                        {
                            "path": "/3-1",
                            "title": "小说爬取",
                            "linkUrl": "novel_crawling.html",
                            "children": []
                        },
                        {
                            "path": "/3-2",
                            "title": "字典管理",
                            "linkUrl": "dict_list.html",
                            "children": []
                        }
                    ]
                },
                {
                    "path": "4",     //菜单项所对应的路由路径
                    "title": "系统设置",     //菜单项名称
                    "icon": "el-icon-setting",
                    "children": [//是否有子菜单，若没有，则为[]
                        {
                            "path": "/4-1",
                            "title": "定时任务",
                            "linkUrl": "scheduled_task.html",
                            "children": []
                        }
                    ]
                }
            ],
            rules: {//校验规则
                userName: [{required: true, message: '用户名为必填项', trigger: 'blur'}],
                password: [{required: true, message: '密码为必填项', trigger: 'blur'}],
                newPassword: [{required: true, message: '新密码为必填项', trigger: 'blur'}]
            }
        },
        methods: {
            // 重置表单
            resetForm() {
                this.formData = {};//重置数据
            },
            logout() {
                // alert("测试注销按钮是否执行")
                axios.get("../logout").then(res => {
                    if (res.data.code == 200) {
                        window.location.href = "http://localhost:9090/"
                    } else {
                        this.$message.error("注销失败!")
                    }
                })
            },
            //添加
            handleEdit() {
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        //发送Ajax请求，修改密码
                        axios.post("/user/updatePassword", this.formData)
                            .then(resp => {
                                if (resp.data.code == 200) {
                                    //修改密码成功
                                    this.$message.success(resp.data.msg);
                                } else {
                                    //修改密码失败
                                    this.$message.error(resp.data.msg);
                                }
                            }).finally(() => {
                            //关闭修改密码弹窗
                            this.dialogFormVisible = false;
                        })
                    } else {
                        this.$message.error("校验失败!")
                    }
                });
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出新增窗口
                this.dialogFormVisible = true;
                this.resetForm();
            }
        }
    });
    $(function () {
        var wd = 200;
        $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
